package com.example.lib_cache.viewmodel;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.baidu.mapapi.search.sug.SuggestionResult;
import com.example.lib_cache.R;
import com.example.lib_cache.model.Address;
import com.example.lib_cache.model.EndPoi;
import com.example.lib_common.util.LiveDataManager;

import java.util.ArrayList;
import java.util.List;

public class EndActivityViewModel extends ViewModel {
    private MutableLiveData<Address> endAddressLiveData;

    private MutableLiveData<List<EndPoi>> endPoiListLiveData;

    public MutableLiveData<Address> getEndAddressLiveData() {
        return endAddressLiveData;
    }

    public void setEndAddressLiveData(Address address) {
        this.endAddressLiveData = LiveDataManager
                .getInstance().with("endAddress",Address.class);
        this.endAddressLiveData.postValue(address);

    }


    public MutableLiveData<List<EndPoi>> getEndPoiListLiveData() {
        return endPoiListLiveData;
    }

    public void setEndPoiListLiveData(List<EndPoi> poiList) {
        this.endPoiListLiveData = new MutableLiveData<>();
        this.endPoiListLiveData.setValue(poiList);
    }


    public void suggestionResultToPoiList(
            List<SuggestionResult.SuggestionInfo> suggestionInfos) {
        List<EndPoi> pois = new ArrayList<>();
        for (int i = 0; i < suggestionInfos.size(); i++) {
            EndPoi poi = new EndPoi();

            poi.setPoiName(suggestionInfos.get(i).getKey());
            poi.setPoiAddress(suggestionInfos.get(i).getAddress());
            poi.setImage(R.drawable.ic_pin_drop_dark_24dp);
            poi.setLatLng(suggestionInfos.get(i).getPt());
            pois.add(poi);
        }

        setEndPoiListLiveData(pois);
    }

    public void loadingData() {
        Address address = LiveDataManager
                .getInstance()
                .with("address", Address.class)
                .getValue();
        Log.d("终点：",address.getCity());
        setEndAddressLiveData(address);

    }
}
